//
//  TextViewController.m
//  BleSDK
//
//  Created by wakeup on 2018/10/26.
//  Copyright © 2018年 mr mao. All rights reserved.
//

#import "TextViewController.h"
#import "BleBaseHeader.h"

@interface TextViewController ()<UITableViewDelegate,UITableViewDataSource,BleManagerDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataArray;//数据源

@end

@implementation TextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"测试项";
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    self.dataArray = @[@"配对",@"查找设备",@"开启摇摇拍照",@"关闭摇摇拍照",@"主界面实时数据",@"获取实时蓝牙信号",@"获取实时心率"];
    bleSelf.delegate = self;
}

#pragma mark - UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TextCell"];
    cell.textLabel.text = self.dataArray[indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        [bleSelf ble_sendBondSystem];
    }
    else if (indexPath.row == 1) {
        [bleSelf ble_sendFindDevice];
    }
    else if (indexPath.row == 2) {
        [bleSelf ble_sendTakePictureWithOn:YES];
    }
    else if (indexPath.row == 3) {
        [bleSelf ble_sendTakePictureWithOn:NO];
    }
    else if (indexPath.row == 4) {
        DateModel *date = [[DateModel alloc] init];
        date.year = 2018;
        date.month = 11;
        date.day = 6;
        date.hour = 16;
        date.minute = 20;
        [bleSelf ble_sendAllDataWithDateModel:date];
    }
    else if (indexPath.row == 5) {
        [bleSelf ble_readRSSI];
    }
    else if (indexPath.row == 6) {
        [bleSelf ble_sendRealTimeDurationHeartWithOn:YES];
    }
}

#pragma mark - BleManagerDelegate
- (void)bleBack_getRealTimeData:(RealTimeDataModel *)realTimeDataModel {
    
}

- (void)bleBack_readRSSI:(NSNumber *)RSSI error:(NSError *)error {

}

- (void)bleBack_getRealTimeDurationHeart:(int)heart {
    NSLog(@"heart = %d",heart);
}

#pragma mark - 懒加载
- (UITableView *)tableView {
    if (_tableView == nil) {
        float width = [UIScreen mainScreen].bounds.size.width;
        float height = [UIScreen mainScreen].bounds.size.height;
        
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, width, height-64) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [[UIView alloc] init];
    }
    return _tableView;
}

@end
